package com.wisemoresystem.seal.action.useapply.search;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_mac;
import com.wisemoresystem.seal.model.t_seal;
import com.wisemoresystem.seal.model.t_seal_use_apply;
import com.wisemoresystem.seal.model.t_use_search_log;
import com.wisemoresystem.seal.model.t_user;
import com.wisemoresystem.seal.service.UseUperSearchService;
import com.wisemoresystem.seal.util.DateTools;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 初审列表，初审历史
 * 复审列表，复审历史
 * @author Administrator
 *
 */
@Controller("ixUseVerify")
@Scope("prototype")
@RequestMapping("/ix/useapply/search/uper")
public class UseVerifyAction extends ProjBaseAction {

	@Autowired
	private UseUperSearchService uService;

	// 市级审核的列表
	@RequestMapping("/city_list")
	public ModelAndView city_list(String srh_reason, String srh_name) {

		List<Map<String, Object>> list = uService.selectUseSealCityList(
				srh_reason, srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/useapply/search/uper/city_list");
		mv.addObject("list", list);
		return mv;
	}

	// 省级审核的列表
	@RequestMapping("/pro_list")
	public ModelAndView pro_list(String srh_reason, String srh_name) {

		List<Map<String, Object>> list = uService.selectUseSealProList(
				srh_reason, srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/useapply/search/uper/pro_list");
		mv.addObject("list", list);
		return mv;
	}

	// 用印的详细情况
	@RequestMapping("/detail")
	public ModelAndView detail(String apply_id) {

		t_seal_use_apply apply = oc.findObjById(apply_id,
				t_seal_use_apply.class);
		t_user user = oc.findObjById(apply.getApply_user(), t_user.class);
		t_seal seal = oc.findObjById(apply.getSeal_id(), t_seal.class);
		t_mac mac = oc.findObjById(apply.getMac_id(), t_mac.class);
		List<Map<String, Object>> list = uService
				.selectUseApplyPpList(apply_id);

		ModelAndView mv = new ModelAndView("/jsp/useapply/search/uper/detail");
		mv.addObject("apply", apply);
		mv.addObject("user", user);
		mv.addObject("seal", seal);
		mv.addObject("mac", mac);
		mv.addObject("list", list);
		return mv;
	}

	// 保存审核记录
	@RequestMapping("/add")
	public ModelAndView detail(t_use_search_log log, String apply_id) {

		log.setBank_id(WebTools.getCurrentBankId());
		log.setUser_id(WebTools.getCurrentUserId());
		log.setSearch_time(DateTools.getTimestampTodayStr());
		
		t_seal_use_apply apply = oc.findObjById(apply_id,
				t_seal_use_apply.class);
		String msg = apply.getVerify_status();
		String mv_msg = "";
		if(msg.equals("已自审")){
			log.setSearch_type("city search");
			mv_msg = "redirect:city_list.htm";
			apply.setVerify_status("市级审核");
			
		}else{
			log.setSearch_type("pro search");
			apply.setVerify_status("省级审核");
			mv_msg = "redirect:pro_list.htm";
		}
		
		oc.saveObj(log);
		oc.updateObj(apply);

		super.setTipMsg("操作成功！", Tip.Type.success);
		ModelAndView mv = new ModelAndView();
		mv.setViewName(mv_msg);
		return mv;
	}
	
	@RequestMapping("/search_list")
	public ModelAndView search_list(String srh_content, String srh_user,
			String srh_start, String srh_end) {

		List<Map<String, Object>> list = uService.selectSearchLogList(
				srh_content, srh_start, srh_end, srh_user, page,"city search");

		ModelAndView mv = new ModelAndView("/jsp/useapply/search/uper/search_list");
		mv.addObject("list", list);
		return mv;
	}
	
	@RequestMapping("/search_pro_list")
	public ModelAndView search_pro_list(String srh_content, String srh_user,
			String srh_start, String srh_end) {

		List<Map<String, Object>> list = uService.selectSearchLogList(
				srh_content, srh_start, srh_end, srh_user, page,"pro search");

		ModelAndView mv = new ModelAndView("/jsp/useapply/search/uper/search_pro_list");
		mv.addObject("list", list);
		return mv;
	}
}
